<template>
	<view>
		<view class="heading1">
            <image class="heading-icon1"  @tap="navigateBack" src="../../static/icon/detail/back.png"></image>
        </view>
		<view>
			<view class="title">用户详情</view>
			<userlist class="userbox" :users="users"></userlist>
		</view>
		<view class="cut-off-rule"></view>
		<view>
			<view class="title">房源详情</view>
			<view class="housebox">
				<rentinglist v-if="house.rentingHeading" :rent='house'></rentinglist>
				<sellhouselist v-if="house.sellHeading" :sell='house'></sellhouselist>
			</view>
		</view>
		<view class="cut-off-rule"></view>
		<view>
			<view class="title">申请时间</view>
			<view class="timetext">申请时间：{{getdate(seehouse.seehouseapplicationTime)}}</view>
			<view class="timetext">申请创建时间：{{getdate(seehouse.seehouseapplicationCreattime)}}</view>
		</view>
		<view v-if="this.seehouse.seehouseapplicationHousestate == 0" class="uni-flex uni-row foot">
			<button class="accept" @tap="accept">接收</button>
			<button class="reject" @tap="reject">拒绝</button>
		</view>
		<view v-else-if="this.seehouse.seehouseapplicationHousestate == 1 && this.seehouse.seehouseapplicationState == 1" class="uni-flex uni-row foot">
			<button class="accept" disabled="disabled">已接收</button>
			<button class="grey" disabled="disabled">拒绝</button>
		</view>
		<view v-else class="uni-flex uni-row foot">
			<button class="grey" disabled="disabled">接收</button>
			<button class="reject" disabled="disabled">已拒绝</button>
		</view>
	</view>
</template>

<script>
import userlist from '../common/userlist.vue'
import rentinglist from '../common/rentinglist.vue'
import sellhouselist from '../common/sellhouselist.vue'
	export default {
		components:{
			userlist,
			rentinglist,
			sellhouselist
		},
		data() {
			return {
				seehouseapplicationId: 1,
				seehouse:{},
				users:{
				},
				house:{}
			}
		},
		methods: {
			getSeehouseByid(){
				let data = {seehouseapplicationId: this.seehouseapplicationId}
				this.$axios.post('getSeehouseByid', this.qs.stringify(data))
				.then(res => {
					this.seehouse = res.data.seehouse[0]
					this.getUserById()
					this.getAllRentingsByHouseId()
					this.getAllSellsByHouseId()
					this.getHouseById()
				})
			},
			getUserById(){
				let data = {userId: this.seehouse.seehouseapplicationApplyerid}
				this.$axios.post('getUserById', this.qs.stringify(data))
				.then(res => {
					this.users = res.data.data
				})
			},
			getAllRentingsByHouseId(){
				let data = {houseId: this.seehouse.houseId}
				this.$axios.post('getAllRentingsByHouseId', this.qs.stringify(data))
				.then(res => {
					this.renting = res.data.allRentings[0]
				})
			},
			getAllSellsByHouseId(){
				let data = {houseId: this.seehouse.houseId}
				this.$axios.post('getAllSellsByHouseId', this.qs.stringify(data))
				.then(res => {
					this.selling = res.data.allSells[0]
				})
			},
			getHouseById(){
				let data = {houseId: this.seehouse.houseId}
				this.$axios.post('getHouseById', this.qs.stringify(data))
				.then(res => {
					this.house = res.data.houses
					Object.assign(this.house, this.renting ,this.selling)
				})
			},
			getdate(time) {
				var now = new Date(time),
					y = now.getFullYear(),
					m = now.getMonth() + 1,
					d = now.getDate();
				// return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
				return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
        	},
			navigateBack(){
            	uni.navigateBack();
  			},
			accept(){
				uni.showModal({  
					title:"申请审核", 
					content:"确定通过申请？",
					showCancel:true,
					success: (res) => {
						this.checkApplication(1)
					} 
				});
			},
			reject(){
				uni.showModal({  
					title:"申请审核", 
					content:"确定拒绝申请？",
					showCancel:true,
					success: (res) => {
						this.checkApplication(0)
					} 
				});
			},
			checkApplication(num){
				this.$axios.post('checkApplication', this.qs.stringify({
					seehouseapplicationId: this.seehouseapplicationId,
					seehouseapplicationState: num
				}))
				.then(res => {
					uni.showToast({
                    title: '审核完成',
                    duration: 2000
                    });
				})
				.then(err =>{
					console.log(err)
				})
			}
		},
        onLoad(option) {
			this.seehouseapplicationId = option.id
            // this.seehouseapplicationId = option.id
			this.getSeehouseByid()
        }
	}
</script>

<style>
.heading1{
	width: 100%;
	background-color: rgba(110, 108, 108, 0);
	height: 100rpx;
}


.heading-icon1{
        height: 80rpx;
        width: 80rpx;
        padding: 10rpx 5rpx 0rpx 0rpx;
}

.title{
	font-size:50rpx;
	padding: 5rpx 10rpx  ;
	text-align: center;
}

.userbox{
	background-color: rgb(255, 255, 255);
	padding: 20rpx 20rpx;
}

.cut-off-rule{
	height: 1rpx;
	width: 90%;
	background-color: rgb(184, 184, 184);
	margin: 40rpx 5%;
}

.housebox{
	background-color: rgb(255, 255, 255);
	padding: 20rpx 20rpx;
}

.timetext{
	font-size: 110%;
	padding: 10rpx 40rpx;
}

.foot{
	padding: 50rpx 20rpx;
}

.accept{
	padding: 0 100rpx;
	background-color: rgb(138, 243, 33);
	color: rgb(255, 255, 255);
	font-size: 130%;
}

.reject{
	padding: 0 100rpx;
	background-color: rgb(255, 28, 73);
	color: rgb(255, 255, 255);
	font-size: 130%;
}

.grey{
	padding: 0 100rpx;
	background-color: rgba(134, 134, 134, 0);
	color: rgb(255, 255, 255);
	font-size: 130%;
}
</style>
